package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
public class EmpController {
    // 注入业务层对象
    @Autowired
    private EmpService empService;

    @GetMapping("/emps")
    public Result queryEmp(EmpQueryParam empQueryRaram) {

        PageResult<Emp> pageResult = empService.queryEmp(empQueryRaram);

        return Result.success(pageResult);
    }

    /**
     *
     * @param emp 1 员工的基本数据   2 员工的工作经历数据  List<EmpExpr> exprList;
     * @return
     */
   //加一个路径参数
    @PostMapping("/emps")
    public Result save(@RequestBody Emp emp) throws Exception {
        log.info("请求参数emp: {}", emp);
        empService.save(emp);
        return Result.success();
    }
    /**
     * 批量删除员工
     */
    @DeleteMapping("/emps")
    public Result delete(@RequestParam List<Integer> ids){
        log.info("批量删除部门: ids={} ", ids);
        empService.deleteByIds(ids);
        return Result.success();
    }
    /**
     * 查询回显
     */
    @GetMapping("/emps/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Emp emp  = empService.getById(id);
        return Result.success(emp);
    }
    @GetMapping("/emps/list")
    public Result listAll(){
        log.info("新开发:");
     List <Emp> listAll  = empService.listAll();
        return  Result.success(listAll);
    }
    /**
     * 更新员工信息
     */
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息, {}", emp);
        empService.update(emp);
        return Result.success();
    }
}











